package com.ftg.learn.rbac.controller;

import com.ftg.learn.rbac.entity.User;
import com.ftg.learn.rbac.service.impl.UserServiceImpl;
import com.ftg.learn.util.BaseController;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author kangjx
 * @since 2022-03-23
 */
@Api(tags = "用户管理列表")
@RestController
@RequestMapping("/rbac/user")
public class UserController extends BaseController<User, UserServiceImpl> {

    /**
     * 登陆功能
     * @param uaccount  用户名
     * @param password  密码
     * @return  map
     */
    @PostMapping("/login")
    public Map<String,Object> login(String uaccount, String password, HttpSession session){
        return super.service.checkUser(uaccount,password,session);
    }

    /**
     * 添加功能  密码加密
     * @param e  用户信息
     * @return
     */
    @PostMapping("/saveForPassword")
    public boolean saveE(@RequestBody User e){
        return super.service.saveForPassword(e);
    }

    /**
     * 冻结
     * @param id  哪个账号
     * @param num 冻结  解冻
     * @return
     */
    @PutMapping("/updateIce/{id}/{num}")
    public boolean updateIce(@PathVariable("id") int id,@PathVariable("num") int num){
        return super.service.updateIce(id,num);
    }

    @PutMapping("/updateUserInfo")
    public boolean updateUserInfo(int uid,String uaccount,String uname){
        return super.service.updateUserInfo(uid,uaccount,uname);
    }

    @PutMapping("/resetPassword")
    public boolean resetPassword(int uid){
        return super.service.resetPassword(uid);
    }

    /**
     * 获得当前登陆成功的这个人的所有权限
     * @return
     */
    @GetMapping("/loginByPermission")
    public String logedByPermssion(HttpSession session){
        String uid = session.getAttribute("uid").toString();
        return super.service.logedByPermssion(Integer.valueOf(uid));
    }

    @GetMapping("/getUserName")
    public String getUserName(HttpSession session){
        return session.getAttribute("username").toString();
    }

}
